package upload;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * @description:
 * @author: jhy
 * @time: 2021/4/17 17:22
 */

//流的工具类
public class StreamUtils {

    //功能：将输入流转换成byte[],即可以把文件的内容读入到byte[]中
    public static byte[] streamToByteArray(InputStream is) throws IOException{

        //创建输出流对象----->数据写入字节数组的输出流
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        byte[] b = new byte[1024];
        int len;
        while ((len = is.read(b)) != -1){
            bos.write(b,0,len);
        }
        byte[] bytes = bos.toByteArray();
        bos.close();
        return bytes;
    }
}
